home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / transaction / interfaces.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  17.2 KB  |  436 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''Transaction Interfaces
  5.  
  6. $Id: interfaces.py 39538 2005-10-20 13:47:55Z philikon $
  7. '''
  8. import zope.interface as zope
  9.  
  10. class ITransactionManager(zope.interface.Interface):
  11.     '''An object that manages a sequence of transactions.
  12.  
  13.     Applications use transaction managers to establish transaction boundaries.
  14.     '''
  15.     
  16.     def begin():
  17.         '''Begin a new transaction.
  18.  
  19.         If an existing transaction is in progress, it will be aborted.
  20.  
  21.         The newTransaction() method of registered synchronizers is called,
  22.         passing the new transaction object.
  23.         '''
  24.         pass
  25.  
  26.     
  27.     def get():
  28.         '''Get the current transaction.
  29.         '''
  30.         pass
  31.  
  32.     
  33.     def commit():
  34.         '''Commit the current transaction.
  35.         '''
  36.         pass
  37.  
  38.     
  39.     def abort():
  40.         '''Abort the current transaction.
  41.         '''
  42.         pass
  43.  
  44.     
  45.     def savepoint(optimistic = False):
  46.         """Create a savepoint from the current transaction.
  47.  
  48.         If the optimistic argument is true, then data managers that
  49.         don't support savepoints can be used, but an error will be
  50.         raised if the savepoint is rolled back.
  51.  
  52.         An ISavepoint object is returned.
  53.         """
  54.         pass
  55.  
  56.     
  57.     def registerSynch(synch):
  58.         """Register an ISynchronizer.
  59.  
  60.         Synchronizers are notified about some major events in a transaction's
  61.         life.  See ISynchronizer for details.
  62.         """
  63.         pass
  64.  
  65.     
  66.     def unregisterSynch(synch):
  67.         """Unregister an ISynchronizer.
  68.  
  69.         Synchronizers are notified about some major events in a transaction's
  70.         life.  See ISynchronizer for details.
  71.         """
  72.         pass
  73.  
  74.  
  75.  
  76. class ITransaction(zope.interface.Interface):
  77.     '''Object representing a running transaction.
  78.  
  79.     Objects with this interface may represent different transactions
  80.     during their lifetime (.begin() can be called to start a new
  81.     transaction using the same instance, although that example is
  82.     deprecated and will go away in ZODB 3.6).
  83.     '''
  84.     user = zope.interface.Attribute('A user name associated with the transaction.\n\n        The format of the user name is defined by the application.  The value\n        is of Python type str.  Storages record the user value, as meta-data,\n        when a transaction commits.\n\n        A storage may impose a limit on the size of the value; behavior is\n        undefined if such a limit is exceeded (for example, a storage may\n        raise an exception, or truncate the value).\n        ')
  85.     description = zope.interface.Attribute('A textual description of the transaction.\n\n        The value is of Python type str.  Method note() is the intended\n        way to set the value.  Storages record the description, as meta-data,\n        when a transaction commits.\n\n        A storage may impose a limit on the size of the description; behavior\n        is undefined if such a limit is exceeded (for example, a storage may\n        raise an exception, or truncate the value).\n        ')
  86.     
  87.     def commit():
  88.         '''Finalize the transaction.
  89.  
  90.         This executes the two-phase commit algorithm for all
  91.         IDataManager objects associated with the transaction.
  92.         '''
  93.         pass
  94.  
  95.     
  96.     def abort():
  97.         '''Abort the transaction.
  98.  
  99.         This is called from the application.  This can only be called
  100.         before the two-phase commit protocol has been started.
  101.         '''
  102.         pass
  103.  
  104.     
  105.     def savepoint(optimistic = False):
  106.         """Create a savepoint.
  107.  
  108.         If the optimistic argument is true, then data managers that don't
  109.         support savepoints can be used, but an error will be raised if the
  110.         savepoint is rolled back.
  111.  
  112.         An ISavepoint object is returned.
  113.         """
  114.         pass
  115.  
  116.     
  117.     def join(datamanager):
  118.         '''Add a data manager to the transaction.
  119.  
  120.         `datamanager` must provide the transactions.interfaces.IDataManager
  121.         interface.
  122.         '''
  123.         pass
  124.  
  125.     
  126.     def note(text):
  127.         '''Add text to the transaction description.
  128.  
  129.         This modifies the `.description` attribute; see its docs for more
  130.         detail.  First surrounding whitespace is stripped from `text`.  If
  131.         `.description` is currently an empty string, then the stripped text
  132.         becomes its value, else two newlines and the stripped text are
  133.         appended to `.description`.
  134.         '''
  135.         pass
  136.  
  137.     
  138.     def setUser(user_name, path = '/'):
  139.         '''Set the user name.
  140.  
  141.         path should be provided if needed to further qualify the
  142.         identified user.  This is a convenience method used by Zope.
  143.         It sets the .user attribute to str(path) + " " + str(user_name).
  144.         This sets the `.user` attribute; see its docs for more detail.
  145.         '''
  146.         pass
  147.  
  148.     
  149.     def setExtendedInfo(name, value):
  150.         '''Add extension data to the transaction.
  151.  
  152.         name is the name of the extension property to set, of Python type
  153.         str; value must be picklable.  Multiple calls may be made to set
  154.         multiple extension properties, provided the names are distinct.
  155.  
  156.         Storages record the extension data, as meta-data, when a transaction
  157.         commits.
  158.  
  159.         A storage may impose a limit on the size of extension data; behavior
  160.         is undefined if such a limit is exceeded (for example, a storage may
  161.         raise an exception, or remove `<name, value>` pairs).
  162.         '''
  163.         pass
  164.  
  165.     
  166.     def beforeCommitHook(_ITransaction__hook, *args, **kws):
  167.         '''Register a hook to call before the transaction is committed.
  168.  
  169.         THIS IS DEPRECATED IN ZODB 3.6.  Use addBeforeCommitHook() instead.
  170.  
  171.         The specified hook function will be called after the transaction\'s
  172.         commit method has been called, but before the commit process has been
  173.         started.  The hook will be passed the specified positional and keyword
  174.         arguments.
  175.  
  176.         Multiple hooks can be registered and will be called in the order they
  177.         were registered (first registered, first called).  This method can
  178.         also be called from a hook:  an executing hook can register more
  179.         hooks.  Applications should take care to avoid creating infinite loops
  180.         by recursively registering hooks.
  181.  
  182.         Hooks are called only for a top-level commit.  A subtransaction
  183.         commit does not call any hooks.  If the transaction is aborted, hooks
  184.         are not called, and are discarded.  Calling a hook "consumes" its
  185.         registration too:  hook registrations do not persist across
  186.         transactions.  If it\'s desired to call the same hook on every
  187.         transaction commit, then beforeCommitHook() must be called with that
  188.         hook during every transaction; in such a case consider registering a
  189.         synchronizer object via a TransactionManager\'s registerSynch() method
  190.         instead.
  191.         '''
  192.         pass
  193.  
  194.     
  195.     def addBeforeCommitHook(hook, args = (), kws = None):
  196.         '''Register a hook to call before the transaction is committed.
  197.  
  198.         The specified hook function will be called after the transaction\'s
  199.         commit method has been called, but before the commit process has been
  200.         started.  The hook will be passed the specified positional (`args`)
  201.         and keyword (`kws`) arguments.  `args` is a sequence of positional
  202.         arguments to be passed, defaulting to an empty tuple (no positional
  203.         arguments are passed).  `kws` is a dictionary of keyword argument
  204.         names and values to be passed, or the default None (no keyword
  205.         arguments are passed).
  206.  
  207.         Multiple hooks can be registered and will be called in the order they
  208.         were registered (first registered, first called).  This method can
  209.         also be called from a hook:  an executing hook can register more
  210.         hooks.  Applications should take care to avoid creating infinite loops
  211.         by recursively registering hooks.
  212.  
  213.         Hooks are called only for a top-level commit.  A subtransaction
  214.         commit or savepoint creation does not call any hooks.  If the
  215.         transaction is aborted, hooks are not called, and are discarded.
  216.         Calling a hook "consumes" its registration too:  hook registrations
  217.         do not persist across transactions.  If it\'s desired to call the same
  218.         hook on every transaction commit, then addBeforeCommitHook() must be
  219.         called with that hook during every transaction; in such a case
  220.         consider registering a synchronizer object via a TransactionManager\'s
  221.         registerSynch() method instead.
  222.         '''
  223.         pass
  224.  
  225.     
  226.     def getBeforeCommitHooks():
  227.         '''Return iterable producing the registered addBeforeCommit hooks.
  228.  
  229.         A triple (hook, args, kws) is produced for each registered hook.
  230.         The hooks are produced in the order in which they would be invoked
  231.         by a top-level transaction commit.
  232.         '''
  233.         pass
  234.  
  235.  
  236.  
  237. class ITransactionDeprecated(zope.interface.Interface):
  238.     '''Deprecated parts of the transaction API.'''
  239.     
  240.     def begin(info = None):
  241.         '''Begin a new transaction.
  242.  
  243.         If the transaction is in progress, it is aborted and a new
  244.         transaction is started using the same transaction object.
  245.         '''
  246.         pass
  247.  
  248.     
  249.     def register(object):
  250.         '''Register the given object for transaction control.'''
  251.         pass
  252.  
  253.  
  254.  
  255. class IDataManager(zope.interface.Interface):
  256.     """Objects that manage transactional storage.
  257.  
  258.     These objects may manage data for other objects, or they may manage
  259.     non-object storages, such as relational databases.  For example,
  260.     a ZODB.Connection.
  261.  
  262.     Note that when some data is modified, that data's data manager should
  263.     join a transaction so that data can be committed when the user commits
  264.     the transaction.
  265.     """
  266.     transaction_manager = zope.interface.Attribute("The transaction manager (TM) used by this data manager.\n\n        This is a public attribute, intended for read-only use.  The value\n        is an instance of ITransactionManager, typically set by the data\n        manager's constructor.\n        ")
  267.     
  268.     def abort(transaction):
  269.         '''Abort a transaction and forget all changes.
  270.  
  271.         Abort must be called outside of a two-phase commit.
  272.  
  273.         Abort is called by the transaction manager to abort transactions
  274.         that are not yet in a two-phase commit.
  275.         '''
  276.         pass
  277.  
  278.     
  279.     def tpc_begin(transaction):
  280.         '''Begin commit of a transaction, starting the two-phase commit.
  281.  
  282.         transaction is the ITransaction instance associated with the
  283.         transaction being committed.
  284.         '''
  285.         pass
  286.  
  287.     
  288.     def commit(transaction):
  289.         '''Commit modifications to registered objects.
  290.  
  291.         Save changes to be made persistent if the transaction commits (if
  292.         tpc_finish is called later).  If tpc_abort is called later, changes
  293.         must not persist.
  294.  
  295.         This includes conflict detection and handling.  If no conflicts or
  296.         errors occur, the data manager should be prepared to make the
  297.         changes persist when tpc_finish is called.
  298.         '''
  299.         pass
  300.  
  301.     
  302.     def tpc_vote(transaction):
  303.         """Verify that a data manager can commit the transaction.
  304.  
  305.         This is the last chance for a data manager to vote 'no'.  A
  306.         data manager votes 'no' by raising an exception.
  307.  
  308.         transaction is the ITransaction instance associated with the
  309.         transaction being committed.
  310.         """
  311.         pass
  312.  
  313.     
  314.     def tpc_finish(transaction):
  315.         """Indicate confirmation that the transaction is done.
  316.  
  317.         Make all changes to objects modified by this transaction persist.
  318.  
  319.         transaction is the ITransaction instance associated with the
  320.         transaction being committed.
  321.  
  322.         This should never fail.  If this raises an exception, the
  323.         database is not expected to maintain consistency; it's a
  324.         serious error.
  325.         """
  326.         pass
  327.  
  328.     
  329.     def tpc_abort(transaction):
  330.         '''Abort a transaction.
  331.  
  332.         This is called by a transaction manager to end a two-phase commit on
  333.         the data manager.  Abandon all changes to objects modified by this
  334.         transaction.
  335.  
  336.         transaction is the ITransaction instance associated with the
  337.         transaction being committed.
  338.  
  339.         This should never fail.
  340.         '''
  341.         pass
  342.  
  343.     
  344.     def sortKey():
  345.         '''Return a key to use for ordering registered DataManagers.
  346.  
  347.         ZODB uses a global sort order to prevent deadlock when it commits
  348.         transactions involving multiple resource managers.  The resource
  349.         manager must define a sortKey() method that provides a global ordering
  350.         for resource managers.
  351.         '''
  352.         pass
  353.  
  354.  
  355.  
  356. class ISavepointDataManager(IDataManager):
  357.     
  358.     def savepoint():
  359.         '''Return a data-manager savepoint (IDataManagerSavepoint).
  360.         '''
  361.         pass
  362.  
  363.  
  364.  
  365. class IDataManagerSavepoint(zope.interface.Interface):
  366.     """Savepoint for data-manager changes for use in transaction savepoints.
  367.  
  368.     Datamanager savepoints are used by, and only by, transaction savepoints.
  369.  
  370.     Note that data manager savepoints don't have any notion of, or
  371.     responsibility for, validity.  It isn't the responsibility of
  372.     data-manager savepoints to prevent multiple rollbacks or rollbacks after
  373.     transaction termination.  Preventing invalid savepoint rollback is the
  374.     responsibility of transaction rollbacks.  Application code should never
  375.     use data-manager savepoints.
  376.     """
  377.     
  378.     def rollback():
  379.         '''Rollback any work done since the savepoint.
  380.         '''
  381.         pass
  382.  
  383.  
  384.  
  385. class ISavepoint(zope.interface.Interface):
  386.     '''A transaction savepoint.
  387.     '''
  388.     
  389.     def rollback():
  390.         """Rollback any work done since the savepoint.
  391.  
  392.         InvalidSavepointRollbackError is raised if the savepoint isn't valid.
  393.         """
  394.         pass
  395.  
  396.     valid = zope.interface.Attribute('Boolean indicating whether the savepoint is valid')
  397.  
  398.  
  399. class InvalidSavepointRollbackError(Exception):
  400.     '''Attempt to rollback an invalid savepoint.
  401.  
  402.     A savepoint may be invalid because:
  403.  
  404.     - The surrounding transaction has committed or aborted.
  405.  
  406.     - An earlier savepoint in the same transaction has been rolled back.
  407.     '''
  408.     pass
  409.  
  410.  
  411. class ISynchronizer(zope.interface.Interface):
  412.     '''Objects that participate in the transaction-boundary notification API.
  413.     '''
  414.     
  415.     def beforeCompletion(transaction):
  416.         '''Hook that is called by the transaction at the start of a commit.
  417.         '''
  418.         pass
  419.  
  420.     
  421.     def afterCompletion(transaction):
  422.         '''Hook that is called by the transaction after completing a commit.
  423.         '''
  424.         pass
  425.  
  426.     
  427.     def newTransaction(transaction):
  428.         """Hook that is called at the start of a transaction.
  429.  
  430.         This hook is called when, and only when, a transaction manager's
  431.         begin() method is called explictly.
  432.         """
  433.         pass
  434.  
  435.  
  436.